Kivy Cookbook by 2015

Kivy Cookbook by 2015

Author:2015
Language: eng
Format: epub
Publisher: Packt Publishing


In the Python file, import the usual package to use Kivy.

Also, import the screen manager package.

Define the class for the buttons' rules.

Define the class for the root widget.

In the __init__() method, create and add two screens to the root widget with different content for each one.

With the help of the following code, add two buttons that will help you switch between the two screens:from kivy.app import App from kivy.lang import Builder from kivy.uix.label import Label from kivy.uix.button import Button from kivy.uix.boxlayout import BoxLayout from kivy.uix.screenmanager import Screen class MButton(Button): pass class MyW(BoxLayout): def __init__(self, **kwargs): super(MyW, self).__init__(**kwargs) s = Screen(name="Hello1") s.add_widget(Label(text="src1")) self.ids.sm.add_widget(s) s = Screen(name="Hello2") s.add_widget(Label(text="src2")) self.ids.sm.add_widget(s) self.ids.buttons.add_widget(MButton( text="Hello1")) self.ids.buttons.add_widget(MButton( text="Hello2")) class e1App(App): def build(self): return MyW() if __name__ == '__main__': e1App().run()



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.